/*
 * @Author: your name
 * @Date: 2021-10-03 08:49:29
 * @LastEditTime: 2021-10-03 10:20:38
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \luogu\1.6二分查找\P1102\main.cpp
 */

#include<iostream>
#include<algorithm>
using namespace std;

//数组最长
const int MAX_LENGTH = 200010;

//快排
void quickSort(int array[],int l,int r);
//二分,0~MAX_LENGTH找不到返回0 找到返回其出现的次数
int binaryFindNum(int array[],int N,int value);

int main(){
    int N,C;
    int N_array[MAX_LENGTH]; //find_num
    int N_array_copy[MAX_LENGTH]; //finded_array
    //input
    cin >> N >> C;
    for(int i=0; i<N; i++){
        cin >> N_array[i];
        N_array_copy[i] = N_array[i] + C;
    }
    //对N_array_copy排序 自己写的递归会超时
    //quickSort(N_array_copy,0,N-1);
    sort(N_array_copy,N_array_copy+N);
    //compute 在数组N_array_copy中寻找N_array[i]
    long long int sum = 0;
    for(int i=0; i<N; i++){
        sum += binaryFindNum(N_array_copy,N,N_array[i]);
    }
    cout << sum << endl;
    return 0;
}

void quickSort(int array[],int l,int r)
{
    if(l < r){
        int left = l;
        int right = r;
        int tem = array[left];//store

        while(left < right){
            //右边小于tem
            while(left < right && array[right] >= tem){
                right--;
            }
            if(left < right){
                array[left++] = array[right];
            }
            //左边大于tem
            while(left < right && array[left] <= tem){
                left++;
            }
            if(left < right){
                array[right--] = array[left];
            }
        }
        //tem归位
        array[left] = tem;
        //有序两边
        quickSort(array,l,left-1);
        quickSort(array,left+1,r);
    }
}

int binaryFindNum(int array[],int N,int value)
{
    int left = 0;
    int right = N-1;
    int mid;
    //左边界
    while(left < right){
        mid = (left+right)/2; //左开
        if(value <= array[mid]){
            right = mid;
        }else{
            left = mid + 1;
        }
    }
    //记录最左边界
    int leftIndex = left;
    //判断是否找到,没找到直接退出,返回0
    if(array[left] != value){
        // cout << "not find:" << value << endl;
        return 0;
    }
    
    //寻找最右边界
    left = 0;
    right = N-1;
    while(left < right){
        mid = (left+right+1)/2; //右开
        if(value < array[mid]){
            right = mid - 1;
        }else{
            left = mid;
        }
    }    
    //最右边界
    int rightIndex = left;

    // cout << "value:" << value << " l:" << leftIndex << " r:" << rightIndex << endl;

    //此时确定有找到 返回数目
    return rightIndex - leftIndex + 1;
}